﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyVoteMVC.Domain;
using System.Data.Entity.ModelConfiguration;

namespace MyVoteMVC.Data.Mapping
{
    public class VT_QuestionsMap : EntityTypeConfiguration<VT_Questions>
    {
        public VT_QuestionsMap()
        {
            // Primary Key
            this.HasKey(t => t.Question_ID);

            // Properties
            this.Property(t => t.Question_ID)
                .IsRequired()
                .HasMaxLength(36);

            this.Property(t => t.Activity_ID)
                .HasMaxLength(36);

            this.Property(t => t.Question_Title)
                .HasMaxLength(100);

            this.Property(t => t.Created_By)
                .HasMaxLength(100);

            this.Property(t => t.Created_Action)
                .HasMaxLength(200);

            this.Property(t => t.Last_Update_By)
                .HasMaxLength(100);

            this.Property(t => t.Last_Update_Action)
                .HasMaxLength(200);

            this.Ignore(t => t.Question_IfMultiItemsText);
            this.Ignore(t => t.Question_IfMustAnswerText);
            this.Ignore(t => t.Question_StatusText);

            // Table & Column Mappings
            this.ToTable("VT_Questions");
            this.Property(t => t.Question_ID).HasColumnName("Question_ID");
            this.Property(t => t.Activity_ID).HasColumnName("Activity_ID");
            this.Property(t => t.Question_No).HasColumnName("Question_No");
            this.Property(t => t.Question_Title).HasColumnName("Question_Title");
            this.Property(t => t.Question_Content).HasColumnName("Question_Content");
            this.Property(t => t.Question_IfMustAnswer).HasColumnName("Question_IfMustAnswer");
            this.Property(t => t.Question_IfMultiItems).HasColumnName("Question_IfMultiItems");
            this.Property(t => t.Question_Status).HasColumnName("Question_Status");
            this.Property(t => t.Created_By).HasColumnName("Created_By");
            this.Property(t => t.Created_Date).HasColumnName("Created_Date");
            this.Property(t => t.Created_Action).HasColumnName("Created_Action");
            this.Property(t => t.Last_Update_By).HasColumnName("Last_Update_By");
            this.Property(t => t.Last_Update_Date).HasColumnName("Last_Update_Date");
            this.Property(t => t.Last_Update_Action).HasColumnName("Last_Update_Action");

            // Relationships
            this.HasRequired(t => t.Activity)
                .WithMany(t => t.Questions)
                .HasForeignKey(d => d.Activity_ID);

        }
    }
}
